package com.tran.app.screen

import android.text.TextUtils
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import com.tran.app.data.CourseSelection
import com.tran.app.viewmodel.CourseScreenVM
import com.tran.app.viewmodel.SCViewModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CourseScreen(padding: Modifier, navCotroller: NavHostController,cid:Int) {
    Scaffold(modifier = Modifier.fillMaxSize(),topBar = {
        TopAppBar(title = { Text(text = "选课学生")},
            navigationIcon = {
                IconButton(onClick = { navCotroller.popBackStack() }) {
                    Icon(imageVector = Icons.Default.ArrowBack, contentDescription = "back")
                }
            })
    }) {padding->
        val vm: CourseScreenVM = viewModel()
        val uistate by vm.uidata.collectAsState()
        vm.update(cid)
        LazyColumn(modifier = Modifier
            .padding(padding)
            .fillMaxSize()) {
            items(uistate){
                Column(modifier = Modifier
                    .padding(start = 10.dp, end = 10.dp)
                    .fillMaxWidth()
                    .drawBehind {
                        drawRect(
                            color = Color.Black, // 选择你需要的颜色
                            topLeft = Offset.Zero,
                            size =this.size,
                            style = Stroke(width = 1.dp.toPx())
                        )
                    }
                    .clickable {
                    }
                    .padding(top = 10.dp, bottom = 10.dp, start = 10.dp), horizontalAlignment = Alignment.Start) {
                    Text(text = "学生姓名:"+it.realName)
                    Text(text = "学生性别:"+it.sex)
                    Text(text = "系:"+it.kind)
                    Text(text = "班级:"+it.grade)
                    Text(text = "邮箱:"+it.email)
                }
            }
        }
    }
}